<template>
    <div>
        <h2>房号修改</h2>
        <table class="table  table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td>
                        <input type="text" v-model="housenook.HouseNoName">
                    </td>
                </tr>


                <tr>
                    <td>房号名称</td>
                    <td>
                        <input type="text"  v-model="housenook.HouseNumber">
                    </td>
                </tr>


                <tr>
                    <td>排序</td>
                    <td>
                        <input type="text"  v-model="housenook.OrderNum">
                    </td>
                </tr>


                 <tr>
                    <td>时间</td>
                    <td>
                        <input type="date"  v-model="housenook.CreateTime">
                    </td>
                </tr>

                
                <tr>
                    <td>备注</td>
                    <td>
                        <textarea cols="50" rows="5"  v-model="housenook.BeiZhu"> </textarea>
                    </td>
                </tr>


                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="state" value="1"  v-model="housenook.State">上架
                        <input type="radio" name="state" value="0"  v-model="housenook.State">下架
                    </td>
                </tr>


                <tr>
                    <td></td>
                    <td>
                        <input type="button" class="btn btn-success" value="修改" @click="ok">
                    </td>
                </tr>

            </tbody>


        </table>

    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
const route = useRoute();
const router = useRouter();


//修改房号
let housenook = reactive({
    Id:route.query.Id,
    "HouseNoName": '',
    "HouseNumber": '',
    "OrderNum": '',
    "CreateTime": '',
    "BeiZhu": '',
    "State": 1,
})



//反填
onMounted(()=>{
    GetAll();
})

const GetAll=()=>{
axios({

url:'https://localhost:7259/api/HouseNo/HouseNoAll',
method:'get',
params: {Id:route.query.Id},
})

.then((res)=>{
    console.log(res);
    housenook.HouseNoName=res.data.HouseNoName;
    housenook.HouseNumber=res.data.HouseNumber;
    housenook.OrderNum=res.data.OrderNum;
    housenook.CreateTime=res.data.CreateTime.substring(0,10);
    
    housenook.BeiZhu=res.data.BeiZhu;
    housenook.State=res.data.State;
    
})


.catch((ree)=>{
    console.log(ree);
})



}





//修改房号
const ok=()=>{

axios({

url:'https://localhost:7259/api/HouseNo/HouseNoUpd',
method:'put',
data:housenook,
})

.then((res)=>{
    console.log(res);
    if(res.data==-1){
        alert("房号已经存在");
        return;
    }
    else if(res.data==1){
        alert("修改成功");
        router.push('/HouseNoList')
    }
    else{
        alert("修改失败");
        return;
    }
})


.catch((ree)=>{
    console.log(ree);
})



}
</script>

<style scoped></style>